package com.chenl.consumer.controller;

import cn.hutool.json.XML;
import com.alibaba.fastjson.JSONObject;
import com.chenl.consumer.DEMOS.幂等注解.UserInfo;
import com.chenl.consumer.feign.ProFeign;
import com.chenl.consumer.vo.Student;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
@RequestMapping("/test3")
public class Controller {

    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    ProFeign proFeign;

//    @Idempotent(key = "#userInfo.student")
    @PostMapping("/test")
    public String test(@RequestBody UserInfo userInfo) throws Exception {
        log.info("消费者进来了");
//        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//        Enumeration<String> er = request.getHeaderNames();
//        while(er.hasMoreElements()){
//            String name	=(String) er.nextElement();
//            String value = request.getHeader(name);
//            log.info(name+"="+value);
//        }

        System.out.println(userInfo);//
        return "666";
    }

    @PostMapping(value = "/testt" )
    public String testt(@RequestBody String student) throws Exception{
        System.out.println(student);
        cn.hutool.json.JSONObject jsonObject = XML.toJSONObject(student);
        Student student1 = JSONObject.parseObject(jsonObject.getStr("Student"), Student.class);
//        System.out.println(jsonObject.getStr("Student"));
        System.out.println(JSONObject.toJSONString(student1));
        return "ok";
    }
}
